﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

public partial class Reports_Verify_trm_out_shift_close : System.Web.UI.Page
{

    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            oHours.SelectedIndex = 2;
            oDays.SelectedIndex = 2;
        }
        Invalidate();
    }
    protected void oBtn_Click(object sender, EventArgs e)
    {
        Invalidate();
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string str = e.Row.Cells[1].Text;
            str = HttpUtility.HtmlDecode(str);
            str = str.Trim();
            DateTime? value = null;
            if (!String.IsNullOrEmpty(str))
                value = DateTime.Parse(str);
            if (value != null)
            {
                str = value.Value.ToShortDateString() + " ; " + value.Value.ToShortTimeString();
                str = HttpUtility.HtmlEncode(str);
                e.Row.Cells[1].Text = str;
            }

            str = e.Row.Cells[2].Text;
            str = HttpUtility.HtmlDecode(str);
            str = str.Trim();
            value = null;
            if (!String.IsNullOrEmpty(str))
                value = DateTime.Parse(str);
            if (value != null)
            {
                str = value.Value.ToShortDateString() + " ; " + value.Value.ToShortTimeString();
                str = HttpUtility.HtmlEncode(str);
                e.Row.Cells[2].Text = str;
            }
        }
    }
    #endregion

    #region Dtata
    void Invalidate()
    {
        int hours = Convert.ToInt32(oHours.Text);
        int days = Convert.ToInt32(oDays.Text);
        DataTable tbl = new DataTable();
        Ko2.DB.MySql o = new Ko2.DB.MySql();
        Exception err = o.Get_trm_out_shift_close(ref tbl, hours, days);
        if (err != null)
        {
            gv.DataSource = null;
            Response.Write(err.Message);
        }
        else
        {
            gv.DataSource = tbl;
            gv.DataBind();
        }
    }
    #endregion    

}